package com.ruoyi.system.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.vo.StudentVo;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TStudentMapper;
import com.ruoyi.system.domain.TStudent;
import com.ruoyi.system.service.ITStudentService;

/**
 * 学生Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-27
 */
@Service
public class TStudentServiceImpl implements ITStudentService 
{
    @Autowired
    private TStudentMapper tStudentMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询学生
     * 
     * @param id 学生主键
     * @return 学生
     */
    @Override
    public TStudent selectTStudentById(Long id)
    {
        return tStudentMapper.selectTStudentById(id);
    }

    /**
     * 查询学生列表
     * 
     * @param tStudent 学生
     * @return 学生
     */
    @Override
    public List<TStudent> selectTStudentList(TStudent tStudent)
    {
        SysUser user = sysUserMapper.selectUserById(SecurityUtils.getUserId());
        if(user.getRoles() != null){
            boolean contains = user.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()).contains(100L);
            if(contains){
                String userName = user.getUserName();
                tStudent.setNumber(userName);
            }
        }
        return tStudentMapper.selectTStudentList(tStudent);
    }

    /**
     * 新增学生
     * 
     * @param tStudent 学生
     * @return 结果
     */
    @Override
    public int insertTStudent(TStudent tStudent)
    {
        return tStudentMapper.insertTStudent(tStudent);
    }

    /**
     * 修改学生
     * 
     * @param tStudent 学生
     * @return 结果
     */
    @Override
    public int updateTStudent(TStudent tStudent)
    {
        return tStudentMapper.updateTStudent(tStudent);
    }

    /**
     * 批量删除学生
     * 
     * @param ids 需要删除的学生主键
     * @return 结果
     */
    @Override
    public int deleteTStudentByIds(Long[] ids)
    {
        return tStudentMapper.deleteTStudentByIds(ids);
    }

    /**
     * 删除学生信息
     * 
     * @param id 学生主键
     * @return 结果
     */
    @Override
    public int deleteTStudentById(Long id)
    {
        return tStudentMapper.deleteTStudentById(id);
    }

    @Override
    public List<StudentVo> getStudents() {
        List<StudentVo> students = tStudentMapper.getStudents();
        return students;
    }
}
